
import 'package:flutter/material.dart';

void main() =>runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context){
    return MaterialApp(
        home:HYHomePage()
    );
  }
}

class HYHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context){
    return Scaffold(
      appBar: AppBar(
        title: Text("商品列表"),
      ),
      body: HYHomeContent("你好啊，黄小腿111"),
    );
  }
}

//Widget 是不加_:暴露给别人使用
class HYHomeContent extends StatefulWidget {
  final String message;
  HYHomeContent(this.message) {
    print('构造函数调用');
  }
  @override
  State<StatefulWidget> createState(){
    print("调用build方法");
    return _HYHomeContentState();
  }
}
/**
 * 为什么Flutter在设计的时候StatefulWidget的build方法在State钟
 * 1、build出来的Wodget是需要依赖State中的变量（状态/数量）
 * 2、在Flutter的运行过程中：反反复复
 *    Widget是不断的销毁和创建的
 *    当我们自己的状态发生改变时，并不希望重新创建一个新的State
 * */
//State是加_:状态这个类是给widget使用
class _HYHomeContentState extends State<HYHomeContent>{
  int _counter = 0;

  @override
  final ButtonStyle style =
  ElevatedButton.styleFrom(textStyle: const TextStyle(fontSize: 20));

  Widget build(BuildContext context){
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          _getButton(),
          Text("当前计数：$_counter",style: TextStyle(fontSize: 25)),
          Text("传递的信息：${widget.message}")
        ],
      ),
    );
  }

  Widget _getButton(){
    return Row(
      children:<Widget> [
        ElevatedButton(
          style:ElevatedButton.styleFrom(
            shadowColor: Colors.blueAccent,
            elevation: 10,
          ),
          onPressed: (){
            setState(() {
              _counter++;
            });
          },
          child: const Text('Disabled1'),
        ),
        const SizedBox(height: 30),
        ElevatedButton(
          style: style,
          onPressed: ()=>print("点击-"),
          child: const Text('Enabled1'),
        ),
      ],
    );
  }
}

